﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.fminutes.vinciIsometric.core {
    import flash.display.*;
    import flash.geom.*;
    import com.fminutes.vinciIsometric.events.*;

    public class IsoObject extends Sprite {

        private var _vector3D:Vector3D;
        private var _floorWidth:Number;
        private var _floorHeight:Number;
        private var _altitude:Number = 0;
        private var _isoID:int = 0;
        private var _isoName:String = "";
        private var _id:String = "";
        private var _direction:int = 0;
        private var _allowableDirection:int = 0;
        private var _layerIndex:int = 0;
        private var _displayChild:DisplayObject;
        private var _type:String = "floor";
        private var _isBottom:Boolean = false;
        private var _isContainer:Boolean = false;
        private var _canPlaced:Boolean = false;
        private var _isWall:Boolean = false;
        private var _wallpaper:Boolean = false;
        private var _isCombo:Boolean = false;
        private var _comboRim:String = "1111";
        private var _canAttached:Boolean = false;
        private var _afloat:Boolean = false;
        private var _walkable:int = 1;
        private var _allowDIY:int = 1;
        private var _other:String = "";
        private var _barrier:Array;
        private var _parentWorld:IsoWorld;
        private var _mouseOverEnabled:Boolean = false;
        private var _isoPositionChanged:Boolean = true;
        private var _isoPosition:IsoPosition;
        private var _maxIsoPosition:IsoPosition;
        private var _size:int = 16;
        private var _offsetX2d:Number = 0;
        private var _offsetY2d:Number = 0;

        public function IsoObject(_arg1:Number, _arg2:Number){
            this._floorWidth = _arg1;
            this._floorHeight = _arg2;
            this._isoID = IsoID.getID();
            this._vector3D = new Vector3D();
        }
        public function destruction():void{
        }
        public function get isoID():int{
            return (this._isoID);
        }
        public function set isoName(_arg1:String):void{
            this._isoName = _arg1;
        }
        public function get isoName():String{
            return (this._isoName);
        }
        public function get id():String{
            return (this._id);
        }
        public function set id(_arg1:String):void{
            this._id = _arg1;
        }
        public function set direction(_arg1:int):void{
            this._direction = IsoUtils.toDirection(_arg1);
            this.directionHandle(_arg1);
        }
        public function get direction():int{
            return (this._direction);
        }
        public function get allowableDirection():int{
            return (this._allowableDirection);
        }
        public function set allowableDirection(_arg1:int):void{
            this._allowableDirection = _arg1;
        }
        public function get layerIndex():int{
            return (this._layerIndex);
        }
        public function set layerIndex(_arg1:int):void{
            this._layerIndex = _arg1;
        }
        public function refresh():void{
        }
        public function set displayChild(_arg1:DisplayObject):void{
            if (((!((this._displayChild == null))) && (this._displayChild.parent))){
                removeChild(this._displayChild);
            };
            if (_arg1 == null){
                return;
            };
            if ((_arg1 is Sprite)){
                (_arg1 as Sprite).mouseEnabled = false;
            };
            _arg1.x = -(this.offsetX2d);
            _arg1.y = -(this.offsetY2d);
            addChild(_arg1);
            this._displayChild = _arg1;
        }
        public function get displayChild():DisplayObject{
            return (this._displayChild);
        }
        protected function directionHandle(_arg1:int):void{
        }
        public function get rect():Rectangle{
            return (new Rectangle(this.x, this.z, this._floorWidth, this._floorHeight));
        }
        public function set type(_arg1:String):void{
            this._type = _arg1;
        }
        public function get type():String{
            return (this._type);
        }
        public function get isBottom():Boolean{
            return (this._isBottom);
        }
        public function set isBottom(_arg1:Boolean):void{
            this._isBottom = _arg1;
        }
        public function set isContainer(_arg1:Boolean):void{
            this._isContainer = _arg1;
        }
        public function get isContainer():Boolean{
            return (this._isContainer);
        }
        public function set canPlaced(_arg1:Boolean):void{
            this._canPlaced = _arg1;
        }
        public function get canPlaced():Boolean{
            return (this._canPlaced);
        }
        public function set isWall(_arg1:Boolean):void{
            this._isWall = _arg1;
        }
        public function get isWall():Boolean{
            return (this._isWall);
        }
        public function get wallpaper():Boolean{
            return (this._wallpaper);
        }
        public function set wallpaper(_arg1:Boolean):void{
            this._wallpaper = _arg1;
        }
        public function set isCombo(_arg1:Boolean):void{
            this._isCombo = _arg1;
        }
        public function get isCombo():Boolean{
            return (this._isCombo);
        }
        public function get comboRim():String{
            return (this._comboRim);
        }
        public function set comboRim(_arg1:String):void{
            this._comboRim = _arg1;
        }
        public function set canAttached(_arg1:Boolean):void{
            this._canAttached = _arg1;
        }
        public function get canAttached():Boolean{
            return (this._canAttached);
        }
        public function set afloat(_arg1:Boolean):void{
            this._afloat = _arg1;
        }
        public function get afloat():Boolean{
            return (this._afloat);
        }
        public function set walkable(_arg1:int):void{
            this._walkable = _arg1;
        }
        public function get walkable():int{
            return (this._walkable);
        }
        public function get allowDIY():int{
            return (this._allowDIY);
        }
        public function set allowDIY(_arg1:int):void{
            this._allowDIY = _arg1;
        }
        public function get other():String{
            return (this._other);
        }
        public function set other(_arg1:String):void{
            this._other = _arg1;
        }
        public function get barrier():Array{
            return (this._barrier);
        }
        public function set barrier(_arg1:Array):void{
            this._barrier = _arg1;
        }
        public function set parentWorld(_arg1:IsoWorld):void{
            this._parentWorld = _arg1;
            if (((!((this._parentWorld == null))) && (!((this._size == this._parentWorld.size))))){
                this._size = this._parentWorld.size;
                this._isoPositionChanged = true;
            };
        }
        public function get parentWorld():IsoWorld{
            return (this._parentWorld);
        }
        public function admissible(_arg1:IsoObject):Boolean{
            return (((this.isContainer) && (_arg1.canPlaced)));
        }
        public function hitTest(_arg1:Number, _arg2:Number):DisplayObject{
            var _local3:Bitmap;
            var _local4:Point;
            var _local5:uint;
            var _local6:uint;
            if ((this.displayChild is Bitmap)){
                _local3 = (this.displayChild as Bitmap);
                if (_local3.bitmapData != null){
                    _local4 = _local3.globalToLocal(new Point(_arg1, _arg2));
                    _local5 = _local3.bitmapData.getPixel32(_local4.x, _local4.y);
                    _local6 = (_local5 & 0xFFFFFF);
                    _local5 = (_local5 >> 24);
                    if ((((_local5 > 170)) || ((_local6 == 0xFF0000)))){
                        return (this);
                    };
                };
            } else {
                if (this.hitTestPoint(_arg1, _arg2, true)){
                    return (this);
                };
            };
            return (null);
        }
        public function get mouseOverEnabled():Boolean{
            return (this._mouseOverEnabled);
        }
        public function set mouseOverEnabled(_arg1:Boolean):void{
            this._mouseOverEnabled = _arg1;
        }
        private function countPosition():void{
            var _local1:int;
            var _local2:int;
            var _local3:int;
            var _local4:int;
            if (this._isoPositionChanged){
                _local1 = int((this.x / this._size));
                _local2 = int((this.z / this._size));
                _local3 = (((this.x + this.floorWidth) - 1) / this._size);
                _local4 = (((this.z + this.floorHeight) - 1) / this._size);
                this._isoPosition = new IsoPosition(_local1, _local2);
                this._maxIsoPosition = new IsoPosition(_local3, _local4);
                this._isoPositionChanged = false;
            };
        }
        public function get isoPosition():IsoPosition{
            this.countPosition();
            return (this._isoPosition);
        }
        public function get isoMaxPosition():IsoPosition{
            this.countPosition();
            return (this._maxIsoPosition);
        }
        public function getIsoPosition2D(_arg1:Number=NaN, _arg2:Number=NaN):IsoPosition{
            if (isNaN(_arg1)){
                _arg1 = this.x2d;
            };
            if (isNaN(_arg2)){
                _arg2 = this.y2d;
            };
            var _local3:Number = _arg1;
            var _local4:Number = _arg2;
            var _local5:Vector3D = IsoUtils.screenToIso(new Point(_local3, _local4));
            var _local6:int = int((_local5.x / this._size));
            var _local7:int = int((_local5.z / this._size));
            _local6 = IsoUtils.toDouble(_local6, IsoWorld.SHOW);
            _local7 = IsoUtils.toDouble(_local7, IsoWorld.SHOW);
            return (new IsoPosition(_local6, _local7));
        }
        public function getIsoMaxPosition2D(_arg1:Number=NaN, _arg2:Number=NaN):IsoPosition{
            var _local3:IsoPosition = this.getIsoPosition2D(_arg1, _arg2);
            var _local4:int = ((this.floorWidth - 1) / this._size);
            var _local5:int = ((this.floorHeight - 1) / this._size);
            var _local6:int = (_local3.x + _local4);
            var _local7:int = (_local3.z + _local5);
            return (new IsoPosition(_local6, _local7));
        }
        public function set altitude(_arg1:Number):void{
            this._altitude = _arg1;
        }
        public function get altitude():Number{
            return (this._altitude);
        }
        private function dispatchPositionChanged():void{
            var _local1:PositionEvent = new PositionEvent(PositionEvent.CHANGED);
            _local1.isoObject = this;
            dispatchEvent(_local1);
        }
        public function set floorWidth(_arg1:Number):void{
            this._floorWidth = _arg1;
            this._isoPositionChanged = true;
            this.dispatchPositionChanged();
        }
        public function get floorWidth():Number{
            if ((((this.direction == 90)) || ((this.direction == 270)))){
                return (this._floorHeight);
            };
            return (this._floorWidth);
        }
        public function set floorHeight(_arg1:Number):void{
            this._floorHeight = _arg1;
            this._isoPositionChanged = true;
            this.dispatchPositionChanged();
        }
        public function get floorHeight():Number{
            if ((((this.direction == 90)) || ((this.direction == 270)))){
                return (this._floorWidth);
            };
            return (this._floorHeight);
        }
        protected function updateScreenPosition():void{
            var _local1:Point = IsoUtils.isoToScreen(this._vector3D);
            super.x = _local1.x;
            super.y = _local1.y;
            this._isoPositionChanged = true;
        }
        private function reXYZ():void{
            this.updateScreenPosition();
            this._isoPositionChanged = true;
            if (((((this.x % this._size) == 0)) && (((this.z % this._size) == 0)))){
                this.dispatchPositionChanged();
            };
        }
        public function set xyz(_arg1:Vector3D):void{
            this._vector3D = _arg1;
            this.reXYZ();
        }
        public function get xyz():Vector3D{
            return (this._vector3D);
        }
        override public function set x(_arg1:Number):void{
            var _local2:Vector3D = this._vector3D.clone();
            _local2.x = _arg1;
            this.xyz = _local2;
        }
        override public function get x():Number{
            return (this._vector3D.x);
        }
        override public function set y(_arg1:Number):void{
            var _local2:Vector3D = this._vector3D.clone();
            _local2.y = _arg1;
            this.xyz = _local2;
        }
        override public function get y():Number{
            return (this._vector3D.y);
        }
        override public function set z(_arg1:Number):void{
            var _local2:Vector3D = this._vector3D.clone();
            _local2.z = _arg1;
            this.xyz = _local2;
        }
        override public function get z():Number{
            return (this._vector3D.z);
        }
        public function set x2d(_arg1:Number):void{
            super.x = _arg1;
        }
        public function get x2d():Number{
            return (super.x);
        }
        public function set y2d(_arg1:Number):void{
            super.y = _arg1;
        }
        public function get y2d():Number{
            return (super.y);
        }
        public function get offsetX2d():Number{
            return (this._offsetX2d);
        }
        public function set offsetX2d(_arg1:Number):void{
            if (this.displayChild != null){
                this.displayChild.x = -(_arg1);
            };
            this._offsetX2d = _arg1;
        }
        public function get offsetY2d():Number{
            return (this._offsetY2d);
        }
        public function set offsetY2d(_arg1:Number):void{
            if (this.displayChild != null){
                this.displayChild.y = -(_arg1);
            };
            this._offsetY2d = _arg1;
        }

    }
}//package com.fminutes.vinciIsometric.core 
